package com.course.app.biz;

import com.course.domain.model.Account;
import com.course.domain.model.Student;
import com.course.domain.model.Teacher;
import com.course.domain.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * Created by Justin on 2017/5/14.
 */
@Component
public class UserBiz {

    private final UserService userService;

    @Autowired
    public UserBiz(UserService userService) {
        this.userService = userService;
    }

    public Student updateStudent(Student student) {
        return userService.updateStudent(student);
    }

    public Account loadAccount(int accountId) {
        return userService.loadAccount(accountId);
    }

    public Student loadStudent(int studentId) {
        Student student = userService.loadStudent(studentId);
        if (student == null) {
            return null;
        }
        Account account = userService.loadAccount(student.getAccountId());
        if (account == null) {
            return null;
        }
        return student;
    }

    public Account loadAccountByUsername(String username) {
        return userService.loadAccountByUsername(username);
    }

    public Teacher loadTeacherByUsername(String username) {
        return userService.loadTeacherByUsername(username);
    }

    public Student loadStudentByAccount(int accountId) {
        return userService.loadStudentByAccount(accountId);
    }

    public Teacher loadTeacherByAccount(int accountId) {
        return userService.loadTeacherByAccount(accountId);
    }
}
